package com.cdwm.mrp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdwm.mrp.common.tools.LayuiResponse;
import com.cdwm.mrp.domain.po.Customer;
import com.cdwm.mrp.mapper.CustomerMapper;
import com.cdwm.mrp.service.CustomerSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @version v1.0
 * @Author: lyw
 * @Date: 2021/8/3
 */
@Service
public class CustomerSerivceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerSerivce {

    @Autowired(required = false)
    private CustomerMapper customerMapper;

    @Override
    public LayuiResponse<?> getCustomerList(Customer customer, Integer page, Integer limit) {
        Page<Customer> pager = new Page<>(page, limit);
        QueryWrapper<Customer> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(
                Objects.nonNull(customer.getCustomerName())&& !Objects.equals("",customer.getCustomerName()),
                "customer_name",customer.getCustomerName())
                .eq(Objects.nonNull(customer.getCustomerContact())&& !Objects.equals("",customer.getCustomerContact()),
                "customer_contact",customer.getCustomerContact());
        Page<Customer> customerPage = customerMapper.selectPage(pager, queryWrapper);
        return LayuiResponse.ok(customerPage.getRecords(),customerPage.getTotal());
    }
}
